|
|
@ -28,17 +28,20 @@ public class MaterialRequestEventHandler |
|
|
|
private readonly IProductionLineAppService _productionLineAppService; |
|
|
|
private readonly IMaterialRequestManager _materialRequestManager; |
|
|
|
private readonly ILocationAppService _locationAppService; |
|
|
|
private readonly IBalanceAppService _balanceAppService; |
|
|
|
|
|
|
|
public MaterialRequestEventHandler( |
|
|
|
IIssueJobAppService issueJobAppService |
|
|
|
, IProductionLineAppService productionLineAppService |
|
|
|
, IMaterialRequestManager materialRequestManager |
|
|
|
, ILocationAppService locationAppService) |
|
|
|
, ILocationAppService locationAppService |
|
|
|
, IBalanceAppService balanceAppService) |
|
|
|
{ |
|
|
|
_issueJobAppService = issueJobAppService; |
|
|
|
_productionLineAppService = productionLineAppService; |
|
|
|
_materialRequestManager = materialRequestManager; |
|
|
|
_locationAppService = locationAppService; |
|
|
|
_balanceAppService = balanceAppService; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -121,14 +124,18 @@ public class MaterialRequestEventHandler |
|
|
|
{ |
|
|
|
var jobs = new List<IssueJobEditInput>(); |
|
|
|
|
|
|
|
var transactionType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.Issue, EnumTransSubType.None).ConfigureAwait(false); |
|
|
|
var toLocationCodes = materialRequest.Details.Select(p => p.ToLocationCode).Distinct().ToList(); |
|
|
|
var toLocations = await _locationAppService.GetByCodesAsync(toLocationCodes).ConfigureAwait(false); |
|
|
|
var transactionType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.Issue, EnumTransSubType.None).ConfigureAwait(false);//库存事务
|
|
|
|
|
|
|
|
foreach (var materialRequestDetail in materialRequest.Details.Where(p => p.ToBeIssuedQty > 0))//如果有还有剩余未叫料的数量 则创建新的任务
|
|
|
|
var toLocationCodes = materialRequest.Details.Select(p => p.ToLocationCode).Distinct().ToList();//所有发送库位的集合
|
|
|
|
var toLocations = await _locationAppService.GetByCodesAsync(toLocationCodes).ConfigureAwait(false);//所有库位的集合
|
|
|
|
|
|
|
|
var materialRequestDetails = materialRequest.Details.Where(p => p.ToBeIssuedQty > 0);//所有还没发送物品的集合
|
|
|
|
foreach (var materialRequestDetail in materialRequestDetails)//如果有还有剩余未叫料的数量 则创建新的任务
|
|
|
|
{ |
|
|
|
var toLocation = toLocations.FirstOrDefault(p => p.Code == materialRequestDetail.ToLocationCode); |
|
|
|
var toLocation = toLocations.FirstOrDefault(p => p.Code == materialRequestDetail.ToLocationCode);//判断目标库位是否存在
|
|
|
|
Check.NotNull(toLocation, "库位代码", $"库位 {materialRequestDetail.ToLocationCode} 不存在"); |
|
|
|
|
|
|
|
//创建详情
|
|
|
|
var jobDetails = await BuildIssueJobDetailInputsAsync(materialRequest, materialRequestDetail, transactionType, toLocation.LocationGroupCode).ConfigureAwait(false); |
|
|
|
if (!jobDetails.Any()) |
|
|
|
{ |
|
|
@ -144,7 +151,7 @@ public class MaterialRequestEventHandler |
|
|
|
jobs.Add(job); |
|
|
|
} |
|
|
|
job.Details.AddRange(jobDetails); |
|
|
|
if (materialRequestDetail.ToBeIssuedQty <= 0) |
|
|
|
if (materialRequestDetail.ToBeIssuedQty < 0) |
|
|
|
{ |
|
|
|
materialRequestDetail.Status = EnumStatus.Close; |
|
|
|
} |
|
|
@ -204,7 +211,7 @@ public class MaterialRequestEventHandler |
|
|
|
Statuses = transactionType.OutInventoryStatuses, |
|
|
|
}; |
|
|
|
//获取推荐库存
|
|
|
|
var recommendList = await BalanceAclService.GetRecommendBalancesAsync(input).ConfigureAwait(false); |
|
|
|
var recommendList = await _balanceAppService.GetRecommendBalancesAsync(input).ConfigureAwait(false); |
|
|
|
//没有推荐库存时 跳过此明细 不生成任务
|
|
|
|
if (recommendList.Count != 0) |
|
|
|
{ |
|
|
@ -215,16 +222,17 @@ public class MaterialRequestEventHandler |
|
|
|
if (materialRequest.UseOnTheWayLocation) |
|
|
|
{ |
|
|
|
//获取在途库
|
|
|
|
var locationDto= await _locationAppService.GetFirstByTypeAsync(EnumLocationType.TRANSPORT).ConfigureAwait(false); |
|
|
|
var locationDto = await _locationAppService.GetFirstByTypeAsync(EnumLocationType.TRANSPORT).ConfigureAwait(false); |
|
|
|
|
|
|
|
detail.OnTheWayLocationCode = locationDto.Code; |
|
|
|
} |
|
|
|
|
|
|
|
jobDetails.Add(detail); |
|
|
|
materialRequestDetail.IssuedQty += recommend.Qty; |
|
|
|
await _materialRequestManager.UpdateDetailsAsync(materialRequest).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return jobDetails; |
|
|
|
} |
|
|
|
|
|
|
@ -240,21 +248,22 @@ public class MaterialRequestEventHandler |
|
|
|
detail.RecommendPackingCode = balance.PackingCode; |
|
|
|
detail.RecommendContainerCode = balance.ContainerCode; |
|
|
|
detail.RecommendSupplierBatch = balance.SupplierBatch; |
|
|
|
detail.RecommendProduceDate= balance.ProduceDate; |
|
|
|
detail.RecommendExpireDate= balance.ExpireDate; |
|
|
|
detail.RecommendLot= balance.Lot; |
|
|
|
detail.RecommendProduceDate=balance.ProduceDate; |
|
|
|
detail.RecommendArriveDate= balance.ArriveDate; |
|
|
|
detail.RecommendProduceDate = balance.ProduceDate; |
|
|
|
detail.RecommendExpireDate = balance.ExpireDate; |
|
|
|
detail.RecommendLot = balance.Lot; |
|
|
|
detail.RecommendProduceDate = balance.ProduceDate; |
|
|
|
detail.RecommendArriveDate = balance.ArriveDate; |
|
|
|
detail.RecommendFromLocationArea = balance.LocationArea; |
|
|
|
detail.RecommendFromLocationCode= balance.LocationCode; |
|
|
|
detail.RecommendFromLocationErpCode= balance.LocationErpCode; |
|
|
|
detail.RecommendFromLocationGroup= balance.LocationGroup; |
|
|
|
detail.RecommendFromWarehouseCode= balance.WarehouseCode; |
|
|
|
detail.RecommendFromLocationCode = balance.LocationCode; |
|
|
|
detail.RecommendFromLocationErpCode = balance.LocationErpCode; |
|
|
|
detail.RecommendFromLocationGroup = balance.LocationGroup; |
|
|
|
detail.RecommendFromWarehouseCode = balance.WarehouseCode; |
|
|
|
detail.RecommendQty = balance.Qty; |
|
|
|
detail.Uom = balance.Uom; |
|
|
|
|
|
|
|
detail.ToLocationCode = materialRequestDetail.ToLocationCode; |
|
|
|
detail.ToLocationErpCode = materialRequestDetail.ToLocationErpCode; |
|
|
|
detail.ToLocationArea= materialRequestDetail.ToLocationArea; |
|
|
|
detail.ToLocationArea = materialRequestDetail.ToLocationArea; |
|
|
|
detail.ToWarehouseCode = materialRequestDetail.ToWarehouseCode; |
|
|
|
detail.ToLocationGroup = materialRequestDetail.ToLocationGroup; |
|
|
|
//detail.Operation = //TODO
|
|
|
|