diff --git a/src/WMS.Web.Domain/Mappers/OutStockMapper.cs b/src/WMS.Web.Domain/Mappers/OutStockMapper.cs index 53323ad4..e6d5ee11 100644 --- a/src/WMS.Web.Domain/Mappers/OutStockMapper.cs +++ b/src/WMS.Web.Domain/Mappers/OutStockMapper.cs @@ -33,6 +33,8 @@ namespace WMS.Web.Domain.Mappers .ForMember(x => x.DetailId, ops => ops.Ignore()) .ForMember(x => x.Qty, ops => ops.Ignore()); CreateMap(); + + CreateMap(); CreateMap(); diff --git a/src/WMS.Web.Domain/Services/OutStockService.cs b/src/WMS.Web.Domain/Services/OutStockService.cs index fee917d4..e8554737 100644 --- a/src/WMS.Web.Domain/Services/OutStockService.cs +++ b/src/WMS.Web.Domain/Services/OutStockService.cs @@ -37,11 +37,13 @@ namespace WMS.Web.Domain.Services private readonly ISerialNumberService _serialNumberService; private readonly IBoxInventoryService _boxInventoryService; private readonly IInventoryInOutDetailsService _inventoryInOutDetailsService; + private readonly IBoxInventoryRepositories _boxInventoryRepositories; public OutStockService(IMapper mapper, ILoginService loginService, IBasicsRepositories transactionRepositories, IOutStockRepositories outStockRepositories, IOutStockTaskRepositories outStockTaskRepositories, IOutStockTaskService outStockTaskService, IErpService erpService, ISerialNumberService serialNumberService, - IBoxInventoryService boxInventoryService, IInventoryInOutDetailsService inventoryInOutDetailsService) + IBoxInventoryService boxInventoryService, IInventoryInOutDetailsService inventoryInOutDetailsService, + IBoxInventoryRepositories boxInventoryRepositories) { _mapper = mapper; _loginService = loginService; @@ -53,6 +55,7 @@ namespace WMS.Web.Domain.Services _serialNumberService = serialNumberService; _boxInventoryService = boxInventoryService; _inventoryInOutDetailsService = inventoryInOutDetailsService; + _boxInventoryRepositories = boxInventoryRepositories; } /// /// 出库单 @@ -73,9 +76,30 @@ namespace WMS.Web.Domain.Services return Result.ReFailure(ResultCodes.OutStockMaterialError); //1.需要验证物料对应箱和序列号是否存在库存 //如果是按箱出库从库存拿取数据 - if(dto.Method==1) + if (dto.Method == 1) { + //获取箱子对应的所有库存 + var boxInventoryList = await _boxInventoryRepositories.GetList(dto.Details.Select(s => s.BoxId).ToList()); + //过滤掉不同仓库和不同组织的 + boxInventoryList = boxInventoryList.Where(w => w.StockCode == outStockTask.StockCode && w.OrgCode == outStockTask.OrgCode).ToList(); + //组装dto + var boxInventoryDetails = boxInventoryList.SelectMany(s => s.Details).ToList(); + foreach (var b in boxInventoryDetails) + { + var num = boxInventoryDetails.Where(w => w.MaterialId == b.MaterialId).Sum(s => s.Qty); + var taskDetail = outStockTask.Details.FirstOrDefault(f => f.MaterialId == b.MaterialId); + if (taskDetail == null) return Result.ReFailure(ResultCodes.BoxOutStockTaskMaterialError); + //箱子里该物料的总数量大于出库单(应出库数量-已出库数量) 不能出库 + if (num > (taskDetail.AccruedQty - taskDetail.RealityQty)) + return Result.ReFailure(ResultCodes.BoxNumberError); + var box = boxInventoryList.FirstOrDefault(f => f.Id == b.Fid); + if (box == null) return Result.ReFailure(ResultCodes.BoxNoData); + var dtod = _mapper.Map(b); + dtod.BoxId = box.BoxId; + dtod.SubStockId = box.SubStockId; + dto.Details.Add(dtod); + } } var mIds = dto.Details.GroupBy(g => g.MaterialId).Select(s => s.Key).ToList(); diff --git a/src/WMS.Web.Domain/Values/ResultCodes.cs b/src/WMS.Web.Domain/Values/ResultCodes.cs index 9f06d53d..0c0ee73f 100644 --- a/src/WMS.Web.Domain/Values/ResultCodes.cs +++ b/src/WMS.Web.Domain/Values/ResultCodes.cs @@ -31,6 +31,8 @@ namespace WMS.Web.Domain.Values public static ValueTuple OutStockTaskAlready = (70004, "任务单已全部出库"); public static ValueTuple OutStockTaskRepeal = (70005, "任务单已作废"); public static ValueTuple MergeNumberError = (70006, "必须选择两个及以上的单合并"); + public static ValueTuple BoxNumberError= (70007, "该批箱数量不符,不能出库"); + public static ValueTuple BoxOutStockTaskMaterialError = (70008, "该批箱物料和出库单中不存在,不能出库"); public static ValueTuple BoxIsTrueShelf = (80000, "该箱已上架,请选择其它箱进行上架!"); public static ValueTuple BoxNoData = (80000, "箱信息不存在");