| | |
| | | using Newtonsoft.Json; |
| | | using AutoMapper; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using SqlSugar; |
| | | using WIDESEA_Common.LocationEnum; |
| | |
| | | { |
| | | public partial class OutboundService : IOutboundService |
| | | { |
| | | |
| | | private readonly IMapper _mapper; |
| | | public IUnitOfWorkManage _unitOfWorkManage { get; } |
| | | |
| | | public IOutboundOrderDetailService OutboundOrderDetailService { get; } |
| | |
| | | private readonly IRepository<Dt_LocationInfo> _locationInfoRepository; |
| | | private readonly IRepository<Dt_StockQuantityChangeRecord> _stockChangeRepository; |
| | | private readonly IRepository<Dt_StockInfoDetail_Hty> _stockDetailHistoryRepository; |
| | | private readonly IFeedbackMesService _feedbackMesService; |
| | | |
| | | public OutboundService(IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService) |
| | | public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | Db = _unitOfWorkManage.GetDbClient(); |
| | | OutboundOrderDetailService = outboundOrderDetailService; |
| | |
| | | _stockChangeRepository = stockChangeRepository; |
| | | _stockDetailHistoryRepository = stockDetailHistoryRepository; |
| | | _basicService = basicService; |
| | | _feedbackMesService = feedbackMesService; |
| | | } |
| | | |
| | | #region åºåºåé
|
| | | /// <summary> |
| | | /// 忣åºåºæä½ |
| | | /// </summary> |
| | |
| | | |
| | | pickedDetails.AddRange(materielPickedDetails.PickedDetails); |
| | | |
| | | decimal allallocatedQuantity = materielCalc.UnallocatedQuantity; |
| | | // æ´æ°åºåºåæç»ï¼å¢å é宿°éï¼ä¸å¢å å·²åºæ°éï¼ |
| | | foreach (var detail in materielCalc.Details) |
| | | { |
| | | if (allallocatedQuantity <= 0) break; |
| | | |
| | | decimal lockQuantity = (detail.OrderQuantity - detail.OverOutQuantity); |
| | | if (lockQuantity < materielCalc.UnallocatedQuantity) |
| | | { |
| | | detail.LockQuantity += lockQuantity; // å¢å é宿°é 䏿´æ° OverOutQuantity å OrderDetailStatusï¼å ä¸ºè¿æ²¡æå®é
åºåº |
| | | outboundOrderDetails.Add(detail); |
| | | materielCalc.UnallocatedQuantity -= lockQuantity; |
| | | } |
| | | else |
| | | { |
| | |
| | | return result; |
| | | } |
| | | |
| | | decimal inputQuantity = request.OutboundQuantity.Value; |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | foreach (var item in selectedDetails) |
| | | { |
| | | inputQuantity -= (item.OrderQuantity - item.MoveQty - item.LockQuantity); |
| | | outboundOrderDetails.Add(item); |
| | | if (inputQuantity <= 0) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | result.MaterielCalculations = new List<MaterielOutboundCalculationDTO>() |
| | | { |
| | | new MaterielOutboundCalculationDTO |
| | |
| | | AssignedQuantity = lockQuantity, |
| | | UnallocatedQuantity = request.OutboundQuantity.Value, |
| | | MovedQuantity = moveQuantity, |
| | | Details = selectedDetails |
| | | Details = outboundOrderDetails |
| | | } |
| | | }; |
| | | |
| | | outboundOrder.Details = outboundOrderDetails; |
| | | } |
| | | |
| | | result.CanOutbound = true; |
| | |
| | | return false; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | #region æ£é |
| | | /// <summary> |
| | | /// åºåºå®æå¤çï¼æ«ææ¡ç æ£ååºåï¼ |
| | | /// </summary> |
| | |
| | | return WebResponseContent.Instance.Error($"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼å·²åºåºï¼{totalAllocatedQuantity}ï¼åé
éï¼{lockInfo.AssignQuantity}ï¼æç»å©ä½ï¼{detailRemainingQuantity}"); |
| | | } |
| | | |
| | | if (actualOutboundQuantity + lockInfo.SortedQuantity > lockInfo.AssignQuantity) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼åºåºé{actualOutboundQuantity + lockInfo.SortedQuantity}大äºåé
é{lockInfo.AssignQuantity}"; |
| | | return WebResponseContent.Instance.Error($"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼åºåºé{actualOutboundQuantity + lockInfo.SortedQuantity}大äºåé
é{lockInfo.AssignQuantity}"); |
| | | } |
| | | //if (actualOutboundQuantity + lockInfo.SortedQuantity > lockInfo.AssignQuantity) |
| | | //{ |
| | | // response.Success = false; |
| | | // response.Message = $"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼åºåºé{actualOutboundQuantity + lockInfo.SortedQuantity}大äºåé
é{lockInfo.AssignQuantity}"; |
| | | // return WebResponseContent.Instance.Error($"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼åºåºé{actualOutboundQuantity + lockInfo.SortedQuantity}大äºåé
é{lockInfo.AssignQuantity}"); |
| | | //} |
| | | |
| | | // 8. 夿æ¯å¦éè¦æå
ï¼å½åºåºæ°éå°äºåºåæ°éæ¶éè¦æå
ï¼ |
| | | bool isUnpacked = actualOutboundQuantity < stockDetail.StockQuantity; |
| | | string newBarcode = string.Empty; |
| | | List<MaterialCodeReturnDTO> returnDTOs = new List<MaterialCodeReturnDTO>(); |
| | | |
| | | // 9. å¼å¯äºå¡ |
| | | _unitOfWorkManage.BeginTran(); |
| | |
| | | // æ ¹æ®æ¯å¦æå
æ§è¡ä¸åçæä½ |
| | | if (isUnpacked) |
| | | { |
| | | newBarcode = PerformUnpackOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault()); |
| | | returnDTOs = PerformUnpackOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault()); |
| | | } |
| | | else |
| | | { |
| | |
| | | // item.OverOutQuantity = item.OrderQuantity - item.MoveQty; |
| | | //} |
| | | |
| | | decimal barcodeQuantity = allocatedQuantity; |
| | | |
| | | if (item.LockQuantity - item.OverOutQuantity >= allocatedQuantity) |
| | | { |
| | | item.OverOutQuantity += allocatedQuantity; |
| | |
| | | } |
| | | else |
| | | { |
| | | barcodeQuantity = item.LockQuantity - item.OverOutQuantity; |
| | | allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity); |
| | | item.OverOutQuantity = item.LockQuantity; |
| | | item.CurrentDeliveryQty = item.LockQuantity; |
| | |
| | | Barcodes barcodes = new Barcodes |
| | | { |
| | | Barcode = request.Barcode, |
| | | Qty = actualOutboundQuantity, |
| | | Qty = barcodeQuantity, |
| | | SupplyCode = stockDetail?.SupplyCode ?? "", |
| | | BatchNo = stockDetail?.BatchNo ?? "", |
| | | Unit = stockDetail?.Unit ?? "" |
| | |
| | | BeforeQuantity = beforeQuantity, |
| | | AfterQuantity = isUnpacked ? actualOutboundQuantity : 0, |
| | | ChangeQuantity = -actualOutboundQuantity, |
| | | IsUnpacked = isUnpacked |
| | | IsUnpacked = isUnpacked, |
| | | MaterialCodes = returnDTOs |
| | | }; |
| | | |
| | | response.Success = true; |
| | | response.Message = isUnpacked ? $"æå
åºåºå®æï¼å·²çææ°æ¡ç ï¼{newBarcode}" : "åºåºå®æ"; |
| | | response.Message = "åºåºå®æ"; |
| | | response.ScannedDetail = scannedDetail; |
| | | response.UpdatedDetails = updateDetails; |
| | | response.NewBarcode = newBarcode; |
| | | |
| | | // æ£æ¥åºåºåæ¯å¦å®æ |
| | | if (CheckOutboundOrderCompleted(request.OrderNo)) |
| | | { |
| | | UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.åºåºå®æ.ObjToInt()); |
| | | |
| | | |
| | | //todo: åä¼ MES |
| | | } |
| | |
| | | /// <param name="beforeQuantity"></param> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | private string PerformUnpackOperation(Dt_StockInfoDetail stockDetail, Dt_StockInfo stockInfo, |
| | | private List<MaterialCodeReturnDTO> PerformUnpackOperation(Dt_StockInfoDetail stockDetail, Dt_StockInfo stockInfo, |
| | | decimal actualOutboundQuantity, OutboundCompleteRequestDTO request, decimal beforeQuantity, int taskNum) |
| | | { |
| | | string newBarcode = GenerateNewBarcode(); |
| | | |
| | | string remark = $"æå
è®°å½ï¼åæ¡ç ï¼{request.Barcode}ï¼åæ°éï¼{stockDetail.StockQuantity}ï¼åºåºæ¡ç ï¼{newBarcode}ï¼ åºåºæ°éï¼{actualOutboundQuantity}ï¼ååºæ¡ç ï¼{request.Barcode}ï¼ååºæ°éï¼{stockDetail.StockQuantity - actualOutboundQuantity},æä½è
ï¼{request.Operator}"; |
| | | |
| | | List<Dt_MaterialCodeInfo> materialCodeInfos = CreateMaterialCodeInfos(stockDetail, newBarcode, actualOutboundQuantity, remark); |
| | | |
| | | List<MaterialCodeReturnDTO> returnDTOs = _mapper.Map<List<MaterialCodeReturnDTO>>(materialCodeInfos); |
| | | |
| | | // ä¿ååå§åºåæç»å°åå²è®°å½ |
| | | Dt_StockInfoDetail_Hty originalHistoryRecord = new Dt_StockInfoDetail_Hty |
| | |
| | | }; |
| | | _stockChangeRepository.AddData(unpackChangeRecord); |
| | | |
| | | return newBarcode; |
| | | return returnDTOs; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="stockDetail"></param> |
| | | /// <param name="newBarcode"></param> |
| | | /// <param name="splitQuantity"></param> |
| | | /// <param name="afterQuantity"></param> |
| | | /// <param name="remark"></param> |
| | | /// <returns></returns> |
| | | private List<Dt_MaterialCodeInfo> CreateMaterialCodeInfos(Dt_StockInfoDetail stockDetail, string newBarcode, decimal splitQuantity, string remark) |
| | | { |
| | | List<Dt_MaterialCodeInfo> materialCodeInfos = new List<Dt_MaterialCodeInfo>(); |
| | | |
| | | Dt_MaterielInfo? materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == stockDetail.MaterielCode); |
| | | |
| | | Dt_MaterialCodeInfo outMaterialCodeInfo = new Dt_MaterialCodeInfo() |
| | | { |
| | | AfterQuantity = splitQuantity, |
| | | BatchNo = stockDetail.BatchNo, |
| | | FactoryArea = stockDetail.FactoryArea, |
| | | MaterialName = materielInfo?.MaterielName ?? stockDetail.MaterielName, |
| | | MaterialSpec = materielInfo?.MaterielSpec ?? "", |
| | | MaterialCode = stockDetail.MaterielCode, |
| | | NewBarcode = newBarcode, |
| | | OldBarcode = stockDetail.Barcode, |
| | | OriginalQuantity = stockDetail.StockQuantity, |
| | | PruchaseOrderNo = stockDetail.OrderNo, |
| | | SuplierCode = stockDetail.SupplyCode, |
| | | Unit = stockDetail.Unit, |
| | | Date = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | Remark = remark |
| | | }; |
| | | materialCodeInfos.Add(outMaterialCodeInfo); |
| | | |
| | | Dt_MaterialCodeInfo returnMaterialCodeInfo = new Dt_MaterialCodeInfo() |
| | | { |
| | | AfterQuantity = stockDetail.StockQuantity - splitQuantity, |
| | | BatchNo = stockDetail.BatchNo, |
| | | FactoryArea = stockDetail.FactoryArea, |
| | | MaterialName = materielInfo?.MaterielName ?? stockDetail.MaterielName, |
| | | MaterialSpec = materielInfo?.MaterielSpec ?? "", |
| | | MaterialCode = stockDetail.MaterielCode, |
| | | NewBarcode = stockDetail.Barcode, |
| | | OldBarcode = stockDetail.Barcode, |
| | | OriginalQuantity = stockDetail.StockQuantity, |
| | | PruchaseOrderNo = stockDetail.OrderNo, |
| | | SuplierCode = stockDetail.SupplyCode, |
| | | Unit = stockDetail.Unit, |
| | | Date = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | Remark = remark |
| | | }; |
| | | |
| | | materialCodeInfos.Add(returnMaterialCodeInfo); |
| | | |
| | | _basicService.MaterielCodeInfoService.Repository.AddData(materialCodeInfos); |
| | | return materialCodeInfos; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°è¯¥æçè¯¥ç©æçææéå®è®°å½ç累计已åºåºæ°é |
| | | /// </summary> |
| | | /// <param name="stockId">åºåID</param> |
| | |
| | | // æ£æ¥æææç»çå·²åºæ°éæ¯å¦é½çäºåæ®æ°é |
| | | return details.All(x => x.OverOutQuantity >= x.OrderQuantity - x.MoveQty); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |