出库箱拣货

This commit is contained in:
18942506660
2023-11-23 15:22:16 +08:00
parent 8cf8dab210
commit 2bb740f15e
3 changed files with 30 additions and 2 deletions

View File

@@ -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;
}
/// <summary>
/// 出库单
@@ -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<SaveOutStockDetailsRequest>(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();